package model.ability;

import java.util.Random;

import model.core.Logger;
import model.entity.Entity;
import model.item.Inventory;
import model.item.InventoryItem;

public class PickPocket extends InteractiveAbility {
	/**
	 * Constructor for PickPocket.
	 * @param name
	 * @param ps
	 * @param mana
	 * @param delay
	 */
	public PickPocket(String name, PassiveSkill ps, int mana, int delay) {
		super(name, ps, mana, delay);
	}

	/**
	 * PickPocket interaction.  Take a random item from the target entity and
	 * place it in the caster's inventory.  If it fails, the target becomes
	 * hostile.
	 */
	public void interactWithTarget(Entity caster, Entity target) {
		if(this.testProbability())
			this.pickPocket(caster, target);
		else{
			target.makeHostile(caster);
			Logger.getInstance().writeToLogger("Ability failed!");
		}
	}
	
	/**
	 * Actual pick-pocket transition.
	 */
	private void pickPocket(Entity target, Entity caster){
		// take a random item from the target's inventory and place it
		// in your own
		Inventory inventory = target.getInventory();
		int size = inventory.size();
		Random random = new Random();
		int index = random.nextInt(size);
		
		InventoryItem stolenItem = inventory.getItem(index);
		caster.pickUpItem(stolenItem);
	}

}
